package com.tzz.controller;

import com.alibaba.fastjson2.JSONObject;
import com.tzz.entity.*;
import com.tzz.exception.PreException;
import com.tzz.service.DoOrderService;
import com.tzz.service.OrderService;
import com.tzz.vo.CreatePreOrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/pre/order")
public class OrderController {
    @Autowired
    OrderService orderService;

    @Autowired
    DoOrderService doOrderService;

    @PostMapping("/create")
    public <T> HttpResult createOrder(@RequestBody CreatePreOrderVo createPreOrderVo) throws PreException {
        orderService.createOrder(createPreOrderVo);
        return HttpResult.success();

    }

    @PostMapping("/do/create")
    public void createDoOrder(@RequestBody DoOrder doOrder){
        System.out.println(doOrder);
        doOrderService.produceDoOrder(doOrder);
    }

    @PostMapping("/query")
    public HttpResult<List<ActivityOrder>> getActivityOrder(@RequestBody String activityId){
        return HttpResult.success(orderService.findActivityOrdersByActivityId(String.valueOf(JSONObject.parse(activityId).get("activityId"))));
    }
}
